{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "E:\\Anaconda3_5_0_0\\lib\\site-packages\\gensim\\utils.py:1212: UserWarning: detected Windows; aliasing chunkize to chunkize_serial\n",
      "  warnings.warn(\"detected Windows; aliasing chunkize to chunkize_serial\")\n"
     ]
    }
   ],
   "source": [
    "import gensim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import logging"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 引入数据集\n",
    "raw_sentences = [u\"the quick brown fox jumps over the lazy dogs\",u\"yoyoyo you go home now to sleep\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "sentences = [ s.split() for s in raw_sentences]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['the', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dogs'],\n",
       " ['yoyoyo', 'you', 'go', 'home', 'now', 'to', 'sleep']]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sentences"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from gensim.models import word2vec"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "??word2vec.Word2Vec()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2018-10-17 15:24:16,540 : INFO : collecting all words and their counts\n",
      "2018-10-17 15:24:16,541 : INFO : PROGRESS: at sentence #0, processed 0 words, keeping 0 word types\n",
      "2018-10-17 15:24:16,542 : INFO : collected 15 word types from a corpus of 16 raw words and 2 sentences\n",
      "2018-10-17 15:24:16,543 : INFO : Loading a fresh vocabulary\n",
      "2018-10-17 15:24:16,544 : INFO : effective_min_count=1 retains 15 unique words (100% of original 15, drops 0)\n",
      "2018-10-17 15:24:16,545 : INFO : effective_min_count=1 leaves 16 word corpus (100% of original 16, drops 0)\n",
      "2018-10-17 15:24:16,546 : INFO : deleting the raw counts dictionary of 15 items\n",
      "2018-10-17 15:24:16,547 : INFO : sample=0.001 downsamples 15 most-common words\n",
      "2018-10-17 15:24:16,548 : INFO : downsampling leaves estimated 2 word corpus (13.7% of prior 16)\n",
      "2018-10-17 15:24:16,549 : INFO : estimated required memory for 15 words and 100 dimensions: 19500 bytes\n",
      "2018-10-17 15:24:16,550 : INFO : resetting layer weights\n",
      "2018-10-17 15:24:16,591 : INFO : training model with 3 workers on 15 vocabulary and 100 features, using sg=0 hs=0 sample=0.001 negative=5 window=5\n",
      "2018-10-17 15:24:16,599 : INFO : worker thread finished; awaiting finish of 2 more threads\n",
      "2018-10-17 15:24:16,600 : INFO : worker thread finished; awaiting finish of 1 more threads\n",
      "2018-10-17 15:24:16,657 : INFO : worker thread finished; awaiting finish of 0 more threads\n",
      "2018-10-17 15:24:16,658 : INFO : EPOCH - 1 : training on 16 raw words (2 effective words) took 0.1s, 33 effective words/s\n",
      "2018-10-17 15:24:16,662 : INFO : worker thread finished; awaiting finish of 2 more threads\n",
      "2018-10-17 15:24:16,663 : INFO : worker thread finished; awaiting finish of 1 more threads\n",
      "2018-10-17 15:24:16,663 : INFO : worker thread finished; awaiting finish of 0 more threads\n",
      "2018-10-17 15:24:16,664 : INFO : EPOCH - 2 : training on 16 raw words (3 effective words) took 0.0s, 1138 effective words/s\n",
      "2018-10-17 15:24:16,668 : INFO : worker thread finished; awaiting finish of 2 more threads\n",
      "2018-10-17 15:24:16,668 : INFO : worker thread finished; awaiting finish of 1 more threads\n",
      "2018-10-17 15:24:16,669 : INFO : worker thread finished; awaiting finish of 0 more threads\n",
      "2018-10-17 15:24:16,670 : INFO : EPOCH - 3 : training on 16 raw words (1 effective words) took 0.0s, 346 effective words/s\n",
      "2018-10-17 15:24:16,673 : INFO : worker thread finished; awaiting finish of 2 more threads\n",
      "2018-10-17 15:24:16,674 : INFO : worker thread finished; awaiting finish of 1 more threads\n",
      "2018-10-17 15:24:16,675 : INFO : worker thread finished; awaiting finish of 0 more threads\n",
      "2018-10-17 15:24:16,676 : INFO : EPOCH - 4 : training on 16 raw words (2 effective words) took 0.0s, 531 effective words/s\n",
      "2018-10-17 15:24:16,682 : INFO : worker thread finished; awaiting finish of 2 more threads\n",
      "2018-10-17 15:24:16,683 : INFO : worker thread finished; awaiting finish of 1 more threads\n",
      "2018-10-17 15:24:16,684 : INFO : worker thread finished; awaiting finish of 0 more threads\n",
      "2018-10-17 15:24:16,686 : INFO : EPOCH - 5 : training on 16 raw words (2 effective words) took 0.0s, 485 effective words/s\n",
      "2018-10-17 15:24:16,687 : INFO : training on a 80 raw words (10 effective words) took 0.1s, 105 effective words/s\n",
      "2018-10-17 15:24:16,688 : WARNING : under 10 jobs per worker: consider setting a smaller `batch_words' for smoother alpha decay\n"
     ]
    }
   ],
   "source": [
    "model = word2vec.Word2Vec(sentences,min_count=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "??model.similarity()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "E:\\Anaconda3_5_0_0\\lib\\site-packages\\ipykernel_launcher.py:1: DeprecationWarning: Call to deprecated `similarity` (Method will be removed in 4.0.0, use self.wv.similarity() instead).\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n",
      "E:\\Anaconda3_5_0_0\\lib\\site-packages\\gensim\\matutils.py:737: FutureWarning: Conversion of the second argument of issubdtype from `int` to `np.signedinteger` is deprecated. In future, it will be treated as `np.int32 == np.dtype(int).type`.\n",
      "  if np.issubdtype(vec.dtype, np.int):\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.04290484"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.similarity(\"lazy\",\"sleep\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "model_save_dir = \"F:\\\\workspace\\\\kaggle\\\\gensim_model\\\\test\\\\test.model\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "??model.save()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2018-10-17 15:29:27,162 : INFO : saving Word2Vec object under F:\\workspace\\kaggle\\gensim_model\\test\\test.model, separately None\n",
      "2018-10-17 15:29:27,163 : INFO : not storing attribute vectors_norm\n",
      "2018-10-17 15:29:27,164 : INFO : not storing attribute cum_table\n",
      "2018-10-17 15:29:27,167 : INFO : saved F:\\workspace\\kaggle\\gensim_model\\test\\test.model\n"
     ]
    }
   ],
   "source": [
    "model.save(model_save_dir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2018-10-17 15:32:06,656 : INFO : loading Word2Vec object from F:\\workspace\\kaggle\\gensim_model\\test\\test.model\n",
      "2018-10-17 15:32:06,658 : INFO : loading wv recursively from F:\\workspace\\kaggle\\gensim_model\\test\\test.model.wv.* with mmap=None\n",
      "2018-10-17 15:32:06,659 : INFO : setting ignored attribute vectors_norm to None\n",
      "2018-10-17 15:32:06,660 : INFO : loading vocabulary recursively from F:\\workspace\\kaggle\\gensim_model\\test\\test.model.vocabulary.* with mmap=None\n",
      "2018-10-17 15:32:06,661 : INFO : loading trainables recursively from F:\\workspace\\kaggle\\gensim_model\\test\\test.model.trainables.* with mmap=None\n",
      "2018-10-17 15:32:06,662 : INFO : setting ignored attribute cum_table to None\n",
      "2018-10-17 15:32:06,663 : INFO : loaded F:\\workspace\\kaggle\\gensim_model\\test\\test.model\n"
     ]
    }
   ],
   "source": [
    "model2 = word2vec.Word2Vec.load(model_save_dir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "E:\\Anaconda3_5_0_0\\lib\\site-packages\\ipykernel_launcher.py:1: DeprecationWarning: Call to deprecated `similarity` (Method will be removed in 4.0.0, use self.wv.similarity() instead).\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n",
      "E:\\Anaconda3_5_0_0\\lib\\site-packages\\gensim\\matutils.py:737: FutureWarning: Conversion of the second argument of issubdtype from `int` to `np.signedinteger` is deprecated. In future, it will be treated as `np.int32 == np.dtype(int).type`.\n",
      "  if np.issubdtype(vec.dtype, np.int):\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "-0.02283599"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model2.similarity(\"dogs\",\"you\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "??word2vec.Text8Corpus()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "text8_dir = \"F:\\\\workspace\\\\kaggle\\\\datasets\\\\text8\\\\text8\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "sentences = word2vec.Text8Corpus(text8_dir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2018-10-17 15:52:32,265 : INFO : collecting all words and their counts\n",
      "2018-10-17 15:52:32,268 : INFO : PROGRESS: at sentence #0, processed 0 words, keeping 0 word types\n",
      "2018-10-17 15:52:37,100 : INFO : collected 253854 word types from a corpus of 17005207 raw words and 1701 sentences\n",
      "2018-10-17 15:52:37,101 : INFO : Loading a fresh vocabulary\n",
      "2018-10-17 15:52:37,354 : INFO : effective_min_count=5 retains 71290 unique words (28% of original 253854, drops 182564)\n",
      "2018-10-17 15:52:37,356 : INFO : effective_min_count=5 leaves 16718844 word corpus (98% of original 17005207, drops 286363)\n",
      "2018-10-17 15:52:37,541 : INFO : deleting the raw counts dictionary of 253854 items\n",
      "2018-10-17 15:52:37,549 : INFO : sample=0.001 downsamples 38 most-common words\n",
      "2018-10-17 15:52:37,551 : INFO : downsampling leaves estimated 12506280 word corpus (74.8% of prior 16718844)\n",
      "2018-10-17 15:52:37,766 : INFO : estimated required memory for 71290 words and 100 dimensions: 92677000 bytes\n",
      "2018-10-17 15:52:37,766 : INFO : resetting layer weights\n",
      "2018-10-17 15:52:38,558 : INFO : training model with 3 workers on 71290 vocabulary and 100 features, using sg=0 hs=0 sample=0.001 negative=5 window=5\n",
      "2018-10-17 15:52:39,563 : INFO : EPOCH 1 - PROGRESS: at 9.52% examples, 1179507 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:40,564 : INFO : EPOCH 1 - PROGRESS: at 19.22% examples, 1194365 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:41,567 : INFO : EPOCH 1 - PROGRESS: at 28.98% examples, 1205122 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:42,570 : INFO : EPOCH 1 - PROGRESS: at 38.74% examples, 1210952 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:43,578 : INFO : EPOCH 1 - PROGRESS: at 47.91% examples, 1197386 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:44,578 : INFO : EPOCH 1 - PROGRESS: at 57.61% examples, 1200645 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:45,580 : INFO : EPOCH 1 - PROGRESS: at 67.43% examples, 1204790 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:46,583 : INFO : EPOCH 1 - PROGRESS: at 77.25% examples, 1205873 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:47,584 : INFO : EPOCH 1 - PROGRESS: at 87.07% examples, 1207740 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:48,590 : INFO : EPOCH 1 - PROGRESS: at 96.88% examples, 1208770 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:48,902 : INFO : worker thread finished; awaiting finish of 2 more threads\n",
      "2018-10-17 15:52:48,904 : INFO : worker thread finished; awaiting finish of 1 more threads\n",
      "2018-10-17 15:52:48,909 : INFO : worker thread finished; awaiting finish of 0 more threads\n",
      "2018-10-17 15:52:48,910 : INFO : EPOCH - 1 : training on 17005207 raw words (12508319 effective words) took 10.3s, 1208635 effective words/s\n",
      "2018-10-17 15:52:49,917 : INFO : EPOCH 2 - PROGRESS: at 9.70% examples, 1198983 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:50,917 : INFO : EPOCH 2 - PROGRESS: at 19.58% examples, 1215070 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:51,919 : INFO : EPOCH 2 - PROGRESS: at 29.34% examples, 1219996 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:52,932 : INFO : EPOCH 2 - PROGRESS: at 38.80% examples, 1210064 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:53,932 : INFO : EPOCH 2 - PROGRESS: at 48.62% examples, 1214384 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:54,934 : INFO : EPOCH 2 - PROGRESS: at 58.38% examples, 1215947 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:55,948 : INFO : EPOCH 2 - PROGRESS: at 68.25% examples, 1216808 words/s, in_qsize 4, out_qsize 1\n",
      "2018-10-17 15:52:56,951 : INFO : EPOCH 2 - PROGRESS: at 78.13% examples, 1217059 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:57,952 : INFO : EPOCH 2 - PROGRESS: at 87.95% examples, 1217680 words/s, in_qsize 6, out_qsize 0\n",
      "2018-10-17 15:52:58,958 : INFO : EPOCH 2 - PROGRESS: at 97.77% examples, 1217377 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:52:59,178 : INFO : worker thread finished; awaiting finish of 2 more threads\n",
      "2018-10-17 15:52:59,182 : INFO : worker thread finished; awaiting finish of 1 more threads\n",
      "2018-10-17 15:52:59,190 : INFO : worker thread finished; awaiting finish of 0 more threads\n",
      "2018-10-17 15:52:59,191 : INFO : EPOCH - 2 : training on 17005207 raw words (12506632 effective words) took 10.3s, 1216757 effective words/s\n",
      "2018-10-17 15:53:00,195 : INFO : EPOCH 3 - PROGRESS: at 9.82% examples, 1216708 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:01,197 : INFO : EPOCH 3 - PROGRESS: at 19.69% examples, 1223120 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:02,198 : INFO : EPOCH 3 - PROGRESS: at 29.45% examples, 1225290 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:03,199 : INFO : EPOCH 3 - PROGRESS: at 38.98% examples, 1219126 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:04,204 : INFO : EPOCH 3 - PROGRESS: at 48.74% examples, 1219639 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:05,207 : INFO : EPOCH 3 - PROGRESS: at 58.50% examples, 1219660 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:06,215 : INFO : EPOCH 3 - PROGRESS: at 68.37% examples, 1221071 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:07,220 : INFO : EPOCH 3 - PROGRESS: at 78.25% examples, 1220399 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:08,222 : INFO : EPOCH 3 - PROGRESS: at 87.36% examples, 1210785 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:09,228 : INFO : EPOCH 3 - PROGRESS: at 97.00% examples, 1209186 words/s, in_qsize 6, out_qsize 0\n",
      "2018-10-17 15:53:09,536 : INFO : worker thread finished; awaiting finish of 2 more threads\n",
      "2018-10-17 15:53:09,543 : INFO : worker thread finished; awaiting finish of 1 more threads\n",
      "2018-10-17 15:53:09,546 : INFO : worker thread finished; awaiting finish of 0 more threads\n",
      "2018-10-17 15:53:09,547 : INFO : EPOCH - 3 : training on 17005207 raw words (12505578 effective words) took 10.4s, 1207905 effective words/s\n",
      "2018-10-17 15:53:10,562 : INFO : EPOCH 4 - PROGRESS: at 9.76% examples, 1197629 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:11,563 : INFO : EPOCH 4 - PROGRESS: at 19.58% examples, 1210752 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:12,568 : INFO : EPOCH 4 - PROGRESS: at 29.10% examples, 1206093 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:13,570 : INFO : EPOCH 4 - PROGRESS: at 38.74% examples, 1208013 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:14,578 : INFO : EPOCH 4 - PROGRESS: at 48.44% examples, 1208234 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:15,587 : INFO : EPOCH 4 - PROGRESS: at 58.02% examples, 1205775 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:16,587 : INFO : EPOCH 4 - PROGRESS: at 67.78% examples, 1208189 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:17,588 : INFO : EPOCH 4 - PROGRESS: at 77.54% examples, 1208056 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:18,596 : INFO : EPOCH 4 - PROGRESS: at 87.42% examples, 1209593 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:19,600 : INFO : EPOCH 4 - PROGRESS: at 97.24% examples, 1210447 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:19,874 : INFO : worker thread finished; awaiting finish of 2 more threads\n",
      "2018-10-17 15:53:19,875 : INFO : worker thread finished; awaiting finish of 1 more threads\n",
      "2018-10-17 15:53:19,879 : INFO : worker thread finished; awaiting finish of 0 more threads\n",
      "2018-10-17 15:53:19,880 : INFO : EPOCH - 4 : training on 17005207 raw words (12506692 effective words) took 10.3s, 1210784 effective words/s\n",
      "2018-10-17 15:53:20,888 : INFO : EPOCH 5 - PROGRESS: at 9.47% examples, 1169648 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:21,891 : INFO : EPOCH 5 - PROGRESS: at 19.34% examples, 1199123 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:22,891 : INFO : EPOCH 5 - PROGRESS: at 29.04% examples, 1207069 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:23,895 : INFO : EPOCH 5 - PROGRESS: at 38.68% examples, 1208436 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:24,902 : INFO : EPOCH 5 - PROGRESS: at 48.50% examples, 1211902 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:25,905 : INFO : EPOCH 5 - PROGRESS: at 58.32% examples, 1214595 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:26,908 : INFO : EPOCH 5 - PROGRESS: at 67.96% examples, 1213392 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:27,910 : INFO : EPOCH 5 - PROGRESS: at 77.72% examples, 1212445 words/s, in_qsize 4, out_qsize 0\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2018-10-17 15:53:28,910 : INFO : EPOCH 5 - PROGRESS: at 87.48% examples, 1212891 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:29,912 : INFO : EPOCH 5 - PROGRESS: at 97.24% examples, 1212947 words/s, in_qsize 5, out_qsize 0\n",
      "2018-10-17 15:53:30,190 : INFO : worker thread finished; awaiting finish of 2 more threads\n",
      "2018-10-17 15:53:30,196 : INFO : worker thread finished; awaiting finish of 1 more threads\n",
      "2018-10-17 15:53:30,199 : INFO : worker thread finished; awaiting finish of 0 more threads\n",
      "2018-10-17 15:53:30,200 : INFO : EPOCH - 5 : training on 17005207 raw words (12506627 effective words) took 10.3s, 1212310 effective words/s\n",
      "2018-10-17 15:53:30,201 : INFO : training on a 85026035 raw words (62533848 effective words) took 51.6s, 1210924 effective words/s\n"
     ]
    }
   ],
   "source": [
    "model3 = word2vec.Word2Vec(sentences)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2018-10-17 15:54:34,758 : INFO : saving Word2Vec object under F:\\workspace\\kaggle\\gensim_model\\test\\test8.model, separately None\n",
      "2018-10-17 15:54:34,759 : INFO : not storing attribute vectors_norm\n",
      "2018-10-17 15:54:34,760 : INFO : not storing attribute cum_table\n",
      "2018-10-17 15:54:35,823 : INFO : saved F:\\workspace\\kaggle\\gensim_model\\test\\test8.model\n"
     ]
    }
   ],
   "source": [
    "model3.save(\"F:\\\\workspace\\\\kaggle\\\\gensim_model\\\\test\\\\test8.model\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "??model3.most_similar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "E:\\Anaconda3_5_0_0\\lib\\site-packages\\ipykernel_launcher.py:1: DeprecationWarning: Call to deprecated `most_similar` (Method will be removed in 4.0.0, use self.wv.most_similar() instead).\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n",
      "2018-10-17 15:56:03,832 : INFO : precomputing L2-norms of word weight vectors\n",
      "E:\\Anaconda3_5_0_0\\lib\\site-packages\\gensim\\matutils.py:737: FutureWarning: Conversion of the second argument of issubdtype from `int` to `np.signedinteger` is deprecated. In future, it will be treated as `np.int32 == np.dtype(int).type`.\n",
      "  if np.issubdtype(vec.dtype, np.int):\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[('woman', 0.7617952823638916),\n",
       " ('girl', 0.6582791209220886),\n",
       " ('creature', 0.5956007242202759),\n",
       " ('person', 0.595389723777771),\n",
       " ('gentleman', 0.5809503793716431),\n",
       " ('bride', 0.5801602602005005),\n",
       " ('god', 0.5766940116882324),\n",
       " ('boy', 0.5757743716239929),\n",
       " ('mortal', 0.5754023194313049),\n",
       " ('evil', 0.5719202756881714)]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model3.most_similar([\"man\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "E:\\Anaconda3_5_0_0\\lib\\site-packages\\ipykernel_launcher.py:1: DeprecationWarning: Call to deprecated `similarity` (Method will be removed in 4.0.0, use self.wv.similarity() instead).\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n",
      "E:\\Anaconda3_5_0_0\\lib\\site-packages\\gensim\\matutils.py:737: FutureWarning: Conversion of the second argument of issubdtype from `int` to `np.signedinteger` is deprecated. In future, it will be treated as `np.int32 == np.dtype(int).type`.\n",
      "  if np.issubdtype(vec.dtype, np.int):\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.7617953"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model3.similarity(\"woman\",\"man\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
